/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JanelaSalas.java
 *
 * Created on Oct 3, 2011, 7:35:39 PM
 */
package gui.janelas;

import java.awt.Dimension;
import java.awt.Toolkit;
import table.ButtonEditor;
import table.ButtonRenderer;
import table.CenterTableCellRenderer;
import table.SalaTableModel;

/**
 *
 * @author arthur
 */
public class JanelaSalas extends javax.swing.JFrame {

    private SalaTableModel model;

    /** Creates new form JanelaSalas */
    public JanelaSalas() {
        this.initComponents();
        
        Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
        
        int w = getSize().width;
        int h = getSize().height;
        int x = (dim.width-w)/2;
        int y = (dim.height-h)/2;

        setLocation(x, y);
        
        this.setTitle("Salas");
        this.configurarTable();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        painelBotoes = new javax.swing.JPanel();
        botaoCriarSala = new javax.swing.JButton();
        painelScroll = new javax.swing.JScrollPane();
        tabela = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        botaoCriarSala.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/add.png"))); // NOI18N
        botaoCriarSala.setText("Criar Sala");
        botaoCriarSala.setMargin(new java.awt.Insets(2, 2, 2, 2));
        botaoCriarSala.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                clicarCriarSala(evt);
            }
        });
        botaoCriarSala.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                clicarBotaoCriarSala(evt);
            }
        });
        painelBotoes.add(botaoCriarSala);

        getContentPane().add(painelBotoes, java.awt.BorderLayout.PAGE_END);

        painelScroll.setPreferredSize(new java.awt.Dimension(350, 400));

        tabela.setFont(new java.awt.Font("Droid Sans Fallback", 0, 12));
        tabela.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tabela.setRowHeight(30);
        tabela.setRowMargin(2);
        tabela.setRowSelectionAllowed(false);
        tabela.setShowVerticalLines(false);
        painelScroll.setViewportView(tabela);

        getContentPane().add(painelScroll, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void clicarBotaoCriarSala(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clicarBotaoCriarSala
    this.criarSala();
}//GEN-LAST:event_clicarBotaoCriarSala

private void clicarCriarSala(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_clicarCriarSala
    // TODO add your handling code here:
}//GEN-LAST:event_clicarCriarSala

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for(javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()){
                if("Nimbus".equals(info.getName())){
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch(ClassNotFoundException ex){
            java.util.logging.Logger.getLogger(JanelaSalas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch(InstantiationException ex){
            java.util.logging.Logger.getLogger(JanelaSalas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch(IllegalAccessException ex){
            java.util.logging.Logger.getLogger(JanelaSalas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch(javax.swing.UnsupportedLookAndFeelException ex){
            java.util.logging.Logger.getLogger(JanelaSalas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new JanelaSalas().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botaoCriarSala;
    private javax.swing.JPanel painelBotoes;
    private javax.swing.JScrollPane painelScroll;
    private javax.swing.JTable tabela;
    // End of variables declaration//GEN-END:variables

    private void criarSala() {
        //this.model.inserir(new Sala("CHEGAE", Sala.ESPERANDO, "Arthur", "Clássico"));
        
        JanelaInicial janela = new JanelaInicial(this, true);
        janela.setVisible(true);
    }

    private void configurarTable() {
        CenterTableCellRenderer renderer = new CenterTableCellRenderer();
        model = new SalaTableModel();
        tabela.setModel(model);

        tabela.getColumnModel().getColumn(0).setPreferredWidth(150);
        //tabela.getColumnModel().getColumn(0).setResizable(false);

        tabela.getColumnModel().getColumn(1).setPreferredWidth(90);
        //tabela.getColumnModel().getColumn(1).setResizable(false);
        tabela.getColumnModel().getColumn(1).setCellRenderer(renderer);

        tabela.getColumnModel().getColumn(2).setPreferredWidth(80);
        //tabela.getColumnModel().getColumn(2).setResizable(false);
        tabela.getColumnModel().getColumn(2).setCellRenderer(renderer);
        
        tabela.getColumnModel().getColumn(3).setPreferredWidth(90);
        //tabela.getColumnModel().getColumn(3).setResizable(false);
        tabela.getColumnModel().getColumn(3).setCellRenderer(renderer);
                
        tabela.getColumnModel().getColumn(4).setPreferredWidth(60);
        //tabela.getColumnModel().getColumn(4).setResizable(false);
        tabela.getColumnModel().getColumn(4).setCellRenderer(new ButtonRenderer());
        tabela.getColumnModel().getColumn(4).setCellEditor(new ButtonEditor());
    }
}
